#pragma once
#include <opencv2/core.hpp>
#include <caffe/net.hpp>
#include "basedetector.h"
class Posenet:public PersonDetector {
public:
	Posenet(const char* prototxt, const char* caffemodel, cv::Size basesize);
	virtual void detect(const cv::Mat& img, std::vector<float>& keypoints, std::vector<int>& shape) override;
	virtual void detect(const cv::Mat& img, std::vector<cv::Point2f>& centers, std::vector<cv::Rect>& rects) override;
	void renderPoseKeypointsCpu(cv::Mat& frame, const std::vector<float>& poseKeypoints, std::vector<int>& keyshape, \
		const float renderThreshold, float scale, const bool blendOriginalFrame=true);
	void forward(const cv::Mat& raw);
	//float scale = 0;
private:
	void reshape(int channel, int height, int width, int batchsize = 1);
	void wrapInputLayer(const cv::Mat& raw);	
	void processFeatureMap();
	void nms(float threshold);
	void connectBodyPartsCpu(const int maxPeaks, const int interMinAboveThreshold, const float interThreshold, \
		const int minSubsetCnt, const float minSubsetScore, const float scaleFactor);
	void renderKeypointsCpu(cv::Mat& frame, const std::vector<float>& keypoints, std::vector<int> keyshape, \
		const std::vector<unsigned int>& pairs, const std::vector<float> colors, const float thicknessCircleRatio, \
		const float thicknessLineRatioWRTCircle, const float threshold, float scale);
	cv::Size baseSize;
	std::shared_ptr<caffe::Net> model;
	std::shared_ptr<caffe::Blob> net_output;
	std::shared_ptr<caffe::Blob> nms_out;
	std::shared_ptr<caffe::Blob> nms_in;
	std::vector<float> keypoints;
	std::vector<int> keyshape;
};